package com.js.service.impl;

import com.js.entity.DVisitor;
import com.js.dao.DVisitorDao;
import com.js.service.DVisitorService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.util.List;
import javax.annotation.Resource;

/**
 * (DVisitor)表服务实现类
 *
 * @author makejava
 * @since 2022-06-15 14:06:58
 */
@Service("dVisitorService")
public class DVisitorServiceImpl implements DVisitorService {
    @Resource
    private DVisitorDao dVisitorDao;

    /**
     * 通过ID查询单条数据
     *
     * @param vId 主键
     * @return 实例对象
     */
    @Override
    public DVisitor queryById(Integer vId) {
        return this.dVisitorDao.queryById(vId);
    }

    /**
     * 分页查询
     *
     * @param dVisitor 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<DVisitor> queryByPage(DVisitor dVisitor, PageRequest pageRequest) {
        long total = this.dVisitorDao.count(dVisitor);
        return new PageImpl<>(this.dVisitorDao.queryAllByLimit(dVisitor, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param dVisitor 实例对象
     * @return 实例对象
     */
    @Override
    public DVisitor insert(DVisitor dVisitor) {
        this.dVisitorDao.insert(dVisitor);
        return dVisitor;
    }

    /**
     * 修改数据
     *
     * @param dVisitor 实例对象
     * @return 实例对象
     */
    @Override
    public DVisitor update(DVisitor dVisitor) {
        this.dVisitorDao.update(dVisitor);
        return this.queryById(dVisitor.getVId());
    }

    /**
     * 通过主键删除数据
     *
     * @param vId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer vId) {
        return this.dVisitorDao.deleteById(vId) > 0;
    }
    /**
    * 查询所有
    * @return 列表
    */
    @Override
    public List<DVisitor> queryAll(){
        return this.dVisitorDao.queryAll();
    }
}
